﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;

namespace WordWonderGame.UI.Man2
{
    public partial class KetQuaUI : UserControl
    {
        public int Diem { get; set; }
        private int thoigian;
        private int dungLienTiep;
        private int saiLienTiep;
        public TraLoiUI tl;
        public event EventHandler QuaMan2Roi;
        public event EventHandler HienDapAn;
        public KetQuaUI()
        {
            InitializeComponent();
            //
            tl = new TraLoiUI();
            Diem = 0;
            dungLienTiep = 0;
            saiLienTiep = 0;
            picDung1.Visible = false;
            picDung3.Visible = false;
            picDung5.Visible = false;
            picDung7.Visible = false;
            picDung8.Visible = false;

            picSai1.Visible = false;
            picSai2.Visible = false;
            picSai3.Visible = false;
            picSai4.Visible = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (thoigian > 0)
            {
                thoigian--;
                lbThoiGian.Text = thoigian.ToString();
                progressBar1.Value = 100 * thoigian / 80;
            }
            else
            {
              
                timer1.Stop();
                //chỗ ni ta muốn gọi phương thức hết giờ từ bên TraLoiUI. giờ làm sao?
                // chỗ mà nó hiện đáp án chỗ nào
                // chen vo day ha.uk
                if (HienDapAn != null)
                {
                    HienDapAn(null, null);
                }
               tl.Hetgio();
                timer3.Start();

            }
        }

        public void StartThoiGian()
        {
            thoigian = 80;
            lbThoiGian.Text = thoigian.ToString();
            timer1.Start();
        }
             public void CongDiem()
        {    
                timer2.Start();
   
        }

        private void timer2_Tick(object sender, EventArgs e)
        {    
                Diem += 100;
                lbDiem.Text = Diem.ToString();
                timer2.Stop();

        }
        public void CongDiemXongGame()
        {
            timer3.Start();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {

            if (thoigian == 0)
            {
                timer3.Stop();
                if (QuaMan2Roi != null)
                {
                    QuaMan2Roi(Diem, null);
                }
            }
            else
            {
                thoigian--;
                if (dungLienTiep == 8)
                {
                    lbThoiGian.Text = thoigian.ToString();
                    progressBar1.Value = 100/80*thoigian;
                    Diem += 3;
                    lbDiem.Text = Diem.ToString();
                }
            }
        }

        public void TraLoiSai()
        {
            SoundPlayer playersai = new SoundPlayer(@"Sound\false.wav");
            playersai.Play();
            saiLienTiep++;
            timer4.Start();
            switch (dungLienTiep)
            {
                case 1:
                    picSai1.Visible = true;
                    break;
                case 2:
                    picSai1.Visible = true;
                    break;
                case 3:
                    picSai2.Visible = true;
                    break;
                case 4:
                    picSai2.Visible = true;
                    break;
                case 5:
                    picSai3.Visible = true;
                    break;
                case 6:
                    picSai3.Visible = true;
                    break;
                case 7:
                    picSai4.Visible = true;
                    break;
                case 8:
                    picSai4.Visible = true;
                    break;

            }
           
        }
        public void TraLoiDung()
        {
            SoundPlayer playerdung = new SoundPlayer(@"Sound\true.wav");
            playerdung.Play();
            dungLienTiep++;
            timer4.Start();
            switch (dungLienTiep)
            {
                case 1:
                    picDung1.Visible = true;
                    break;
                case 2:
                    picDung1.Visible = true;
                    break;
                case 3:
                    picDung3.Visible = true;
                    break;
                case 4:
                    picDung3.Visible = true;
                    break;
                case 5:
                    picDung5.Visible = true;
                    break;
                case 6:
                    picDung5.Visible = true;
                    break;
                case 7:
                    picDung7.Visible = true;
                    break;
                case 8:
                    picDung7.Visible = true;
                    break;

            }
        }

        private void timer4_Tick(object sender, EventArgs e)
        {
            picDung1.Visible = false;
            picDung3.Visible = false;
            picDung5.Visible = false;
            picDung7.Visible = false;
            picDung8.Visible = false;

            picSai1.Visible = false;
            picSai2.Visible = false;
            picSai3.Visible = false;
            picSai4.Visible = false;
            timer4.Stop();
        }

        

       
    }
}

        

